//
//  TNNewNotificationViewController.m
//  跑跑快销
//
//  Created by ylife on 14-5-4.
//  Copyright (c) 2014年 ylife. All rights reserved.
//

#import "TNNewNotificationViewController.h"
#import "LXCustomActionSheet.h"

@interface TNNewNotificationViewController ()

@end

@implementation TNNewNotificationViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.title = @"新建通知";
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    _newNotificationView = [[TNNewNotificationView alloc]init];
    self.view = _newNotificationView;
    
    //添加导航栏右键
    UIBarButtonItem *rightButton = [[UIBarButtonItem alloc]initWithTitle:@"发布" style:UIBarButtonItemStylePlain target:self action:@selector(sendOnNewNotification)];
    [self.navigationItem setRightBarButtonItem:rightButton];
    
    //更改返回按钮标题
    UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] init];
    backBarButtonItem.title = @"返回";
    self.navigationItem.backBarButtonItem = backBarButtonItem;
    
     _msgArray = @[@"普通通知",@"紧急通知",@"再接再厉",@"公开表彰",@"通告批评"];
    
    _newNotificationView.kindLable.text = @"通知类型";
    [_newNotificationView.selectButton setTitle:_msgArray[0] forState:UIControlStateNormal];
    [_newNotificationView.selectButton setImage:[UIImage imageNamed:@"c.png"] forState:UIControlStateNormal];
    [_newNotificationView.selectButton addTarget:self action:@selector(chooseKind) forControlEvents:UIControlEventTouchUpInside];
    
    // Do any additional setup after loading the view.
   
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)sendOnNewNotification
{
    NSLog(@"发布！");
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"确认发布？" message: nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    [alertView show];
    [self.view endEditing:YES];
}

- (void)chooseKind
{
    NSLog(@"选择类型");
    NSLog(@"%f",self.view.frame.size.height);
    
    LXCustomActionSheet *sheet = [[LXCustomActionSheet alloc]initWithTitle:@"通知类型" withIconArray:nil withMsgArray:_msgArray withBtnTitle:nil withSelectArray:nil];
    
    sheet.delegate = self;
    [sheet showInView:self.view];
}

#pragma mark - actionSheet代理方法
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    LXCustomActionSheet *sheet = (LXCustomActionSheet *)actionSheet;
    if (buttonIndex >= 1 && buttonIndex <= sheet.messageArray.count) {
        NSString *msg = sheet.messageArray[buttonIndex - 1];
        [_newNotificationView.selectButton setTitle:msg forState:UIControlStateNormal];
    }
    
}


@end
